package com.waidi.clothespad.common;

import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.media.AudioManager;
import android.media.MediaPlayer;

import com.waidi.clothespad.R;

import java.io.IOException;

public class AudioPlay
{



    /**

      * 监听系统静音模式

      * @param mContext

      */

    private void modeIndicater(Context mContext){

        AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);

        final int ringerMode = am.getRingerMode();

        switch (ringerMode) {

            case AudioManager.RINGER_MODE_NORMAL://普通模式

                playFromRawFile(mContext);

                break;

            case AudioManager.RINGER_MODE_VIBRATE://静音模式

                break;

            case AudioManager.RINGER_MODE_SILENT://震动模式

                break;

        }

    }


    /**

      * 提示音

      * @param mContext

      */

    private static  void playFromRawFile(Context mContext) {

        try {

            MediaPlayer player = new MediaPlayer();

            AssetFileDescriptor file = mContext.getResources().openRawResourceFd(R.raw.tiemout);

            try {

                player.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());

                file.close();

                if (!player.isPlaying())
                {
                    player.prepare();
                    player.start();
                }

            } catch (IOException e) {

                player = null;

            }

        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

    }
}
